<!--
 * @Author: 李兵 964368540@qq.com
 * @Date: 2024-11-11 15:57:15
 * @LastEditors: libing 9852442+liu-sheng-8667@user.noreply.gitee.com
 * @LastEditTime: 2024-12-03 09:39:40
 * @FilePath: \crm\pagesform\form\address-list.vue
 * @Description: 收货人地址列表
-->
<template>
  <view>
    <scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="lower">
      <!-- 无限滚动列表 -->
      <view
        v-for="(item, index) in list"
        :key="index"
        class="wrap"
       
      >
        <view @click="onChoose(item)">
           <view class="item-name">{{ item.name }}</view>
           <view class="item-phone">{{ item.phone }}</view>
           <view class="item-detail">{{ item.detailAddress }}</view>
           <view class="item-detail">{{ item.building||'' }}</view>
        </view>
        <view class="item-btn-wrap">
             <view class="item-btn" @click="onUpdate(item)">编辑</view>
             <view class="item-btn" @click="onDel(item)">删除</view>
        </view>
      </view>
      <u-loadmore iconType="circle" :status="status" />
    </scroll-view>
    <bottombox>
      <u-button type="error" text="新增收货地址" @click="onSumbit"></u-button>
    </bottombox>
  </view>
</template>
<script>
import { getAddressList, delAddress } from "@/apis/order/index";
import listPageMixins from "@/pagescustomer/customer/mixins/scroll-list";
export default {
  name: "address-list",
  data() {
    return {
      list: [],
      queryAPI: getAddressList,
      customId: "",
    };
  },
  onLoad(data) {
    this.customId = data.customId;
    this.defaltParams = {
      customId: data.customId,
    };
  },
  mixins: [listPageMixins],
  onShow() {
    this.upper();
  },
  methods: {
    // 新增
    onSumbit() {
      uni.navigateTo({
        url: "/pagesform/form/add-address-form?customId=" + this.customId,
      });
    },
    // 修改
    onUpdate(item) {
      const itemStr = JSON.stringify(item)
      uni.navigateTo({
        url: "/pagesform/form/add-address-form?customId=" + this.customId+'&item='+itemStr,
      });
    },
    // 删除
    onDel(item) {
      uni.showModal({
        title: "提示",
        content: "确认删除吗？",
        success: async (res) => {
          if (res.confirm) {
            await delAddress([item.id])
           this.upper()
          }
        },
      });
    },
    onChoose(data) {
      // 返回上一页面
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2]; //上一个页面
      prevPage.$vm.backUpdatePages({
        //调用A页面的backUpdatePages方法传参
        ...data,
      });
      uni.navigateBack({
        delta: 1, // delta值为1时表示返回上一级页面
      });
    },
  },
};
</script>
<style scoped lang="scss">
.scroll-Y {
  height: 100vh;
}
.wrap {
  margin: 16rpx;
  padding: 20rpx;
  background: #ffffff;
}
.item {
  &-name {
    margin-bottom: 10px;
    font-size: 16px;
  }
  &-phone {
    margin-bottom: 10px;
    font-size: 14px;
    color: #cccccc;
  }
  &-detail {
    font-size: 14px;
    color: #cccccc;
  }
  &-btn-wrap {
    display: flex;
    text-align: right;
    justify-content: flex-end;
    font-size: 14px;

  }
  &-btn {
    margin-left: 20rpx;
  }
}
</style>
